package com.hmy.cornpestdet.config;

import com.hmy.cornpestdet.utils.LoginCheckInterceptors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {
    //设置本地图片路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // /images/**是静态映射， file:/root/images/是文件在服务器的路径
        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:E:/coding/project/project java/CornPestDet/src/main/resources/static/images");
    }
    //设置拦截器
    @Autowired
    private LoginCheckInterceptors loginCheckInterceptors;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        WebMvcConfigurer.super.addInterceptors(registry);
        registry.addInterceptor(loginCheckInterceptors).addPathPatterns("/**")
                .excludePathPatterns("/images/**")//获取图片资源不检查
                .excludePathPatterns("/login/**")//登录是不检查
                .excludePathPatterns("/register/**");//注册时不检查
    }
}

